<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
<!--      <el-form-item label="工号" prop="jobNum">-->
<!--        <el-input-->
<!--          v-model="queryParams.jobNum"-->
<!--          placeholder="请输入工号"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="部门" prop="companyDept">
        <el-input
          v-model="queryParams.companyDept"
          placeholder="请输入部门"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="授权类型" prop="authorizedType">-->
<!--        <el-input-->
<!--          v-model="queryParams.authorizedType"-->
<!--          placeholder="请输入授权类型"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="授权时间" prop="crtime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.crtime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择授权时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="姓名" prop="jobName">
        <el-input
          v-model="queryParams.jobName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="刷脸权限" prop="facePermission">-->
<!--        <el-input-->
<!--          v-model="queryParams.facePermission"-->
<!--          placeholder="请输入刷脸权限"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="刷卡权限" prop="idcardPermission">-->
<!--        <el-input-->
<!--          v-model="queryParams.idcardPermission"-->
<!--          placeholder="请输入刷卡权限"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="人卡合一权限" prop="faceandcardpermission">-->
<!--        <el-input-->
<!--          v-model="queryParams.faceandcardpermission"-->
<!--          placeholder="请输入人卡合一权限"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="人证比对权限" prop="idpermission">-->
<!--        <el-input-->
<!--          v-model="queryParams.idpermission"-->
<!--          placeholder="请输入人证比对权限"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="性别" prop="jobSex">-->
<!--        <el-select v-model="queryParams.jobSex" placeholder="请选择性别" clearable size="small">-->
<!--          <el-option-->
<!--            v-for="dict in jobSexOptions"-->
<!--            :key="dict.dictValue"-->
<!--            :label="dict.dictLabel"-->
<!--            :value="dict.dictValue"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
     、
<!--      <el-form-item label="设备方向" prop="deviceDirection">-->
<!--        <el-select v-model="queryParams.deviceDirection" placeholder="请选择设备方向" clearable size="small">-->
<!--          <el-option-->
<!--            v-for="dict in deviceDirectionOptions"-->
<!--            :key="dict.dictValue"-->
<!--            :label="dict.dictLabel"-->
<!--            :value="dict.dictValue"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="设备ip" prop="deviceIp">-->
<!--        <el-input-->
<!--          v-model="queryParams.deviceIp"-->
<!--          placeholder="请输入设备ip"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="身份证照片" prop="idPhoto">-->
<!--        <el-input-->
<!--          v-model="queryParams.idPhoto"-->
<!--          placeholder="请输入身份证照片"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="身份证号码" prop="idNo">
        <el-input
          v-model="queryParams.idNo"
          placeholder="请输入身份证号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['lgdz:devicepersonauthorizedrecord:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['lgdz:devicepersonauthorizedrecord:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['lgdz:devicepersonauthorizedrecord:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['lgdz:devicepersonauthorizedrecord:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="devicepersonauthorizedrecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="工号" align="center" prop="jobNum" />
      <el-table-column label="部门" align="center" prop="companyDept" />
      <el-table-column label="授权类型" align="center" prop="authorizedType" />
      <el-table-column label="授权时间" align="center" prop="crtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.crtime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="jobName" />
      <el-table-column label="刷脸权限" align="center" prop="facePermission" />
      <el-table-column label="刷卡权限" align="center" prop="idcardPermission" />
      <el-table-column label="人卡合一权限" align="center" prop="faceandcardpermission" width="100"/>
      <el-table-column label="人证比对权限" align="center" prop="idpermission" width="100"/>
      <el-table-column label="性别" align="center" prop="jobSex" :formatter="jobSexFormat" />
      <el-table-column label="授权照片" align="center" prop="authorizedPhotoFirst" width="110">
        <template slot-scope="scope">
          <img :src="scope.row.authorizedPhotoFirst" style="width: 80px;height: 100px">
        </template>
      </el-table-column>
<!--      <el-table-column label="授权照片二" align="center" prop="authorizedPhotoSecond" width="110"/>-->
<!--      <el-table-column label="授权照片三" align="center" prop="authorizedPhotoThird" width="110"/>-->
      <el-table-column label="授权设备序列号" align="center" prop="deviceSno" width="160"/>
      <el-table-column label="授权设备名称" align="center" prop="deviceName" width="100"/>
      <el-table-column label="设备方向" align="center" prop="deviceDirection" :formatter="deviceDirectionFormat" />
      <el-table-column label="设备ip" align="center" prop="deviceIp" width="120"/>
      <el-table-column label="身份证照片" align="center" prop="idPhoto" width="90">
        <template slot-scope="scope">
          <img :src="scope.row.idPhoto" alt :style="{width: '80px', 'height': '100px'}">
        </template>
      </el-table-column>
      <el-table-column label="身份证号码" align="center" prop="idNo" width="160"/>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['lgdz:devicepersonauthorizedrecord:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['lgdz:devicepersonauthorizedrecord:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改人员授权设备记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="工号" prop="jobNum">
          <el-input v-model="form.jobNum" placeholder="请输入工号" />
        </el-form-item>
        <el-form-item label="部门" prop="companyDept">
          <el-input v-model="form.companyDept" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="授权类型" prop="authorizedType">
          <el-input v-model="form.authorizedType" placeholder="请输入授权类型" />
        </el-form-item>
        <el-form-item label="授权时间" prop="crtime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.crtime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择授权时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="姓名" prop="jobName">
          <el-input v-model="form.jobName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="刷脸权限" prop="facePermission">
          <el-input v-model="form.facePermission" placeholder="请输入刷脸权限" />
        </el-form-item>
        <el-form-item label="刷卡权限" prop="idcardPermission">
          <el-input v-model="form.idcardPermission" placeholder="请输入刷卡权限" />
        </el-form-item>
        <el-form-item label="人卡合一权限" prop="faceandcardpermission">
          <el-input v-model="form.faceandcardpermission" placeholder="请输入人卡合一权限" />
        </el-form-item>
        <el-form-item label="人证比对权限" prop="idpermission">
          <el-input v-model="form.idpermission" placeholder="请输入人证比对权限" />
        </el-form-item>
        <el-form-item label="性别">
          <el-select v-model="form.jobSex" placeholder="请选择性别">
            <el-option
              v-for="dict in jobSexOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="授权照片一" prop="authorizedPhotoFirst">
          <el-input v-model="form.authorizedPhotoFirst" placeholder="请输入授权照片一" />
        </el-form-item>
        <el-form-item label="授权照片二" prop="authorizedPhotoSecond">
          <el-input v-model="form.authorizedPhotoSecond" placeholder="请输入授权照片二" />
        </el-form-item>
        <el-form-item label="授权照片三" prop="authorizedPhotoThird">
          <el-input v-model="form.authorizedPhotoThird" placeholder="请输入授权照片三" />
        </el-form-item>
        <el-form-item label="授权设备序列号" prop="deviceSno">
          <el-input v-model="form.deviceSno" placeholder="请输入授权设备序列号" />
        </el-form-item>
        <el-form-item label="授权设备名称" prop="deviceName">
          <el-input v-model="form.deviceName" placeholder="请输入授权设备名称" />
        </el-form-item>
        <el-form-item label="设备方向">
          <el-select v-model="form.deviceDirection" placeholder="请选择设备方向">
            <el-option
              v-for="dict in deviceDirectionOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设备ip" prop="deviceIp">
          <el-input v-model="form.deviceIp" placeholder="请输入设备ip" />
        </el-form-item>
        <el-form-item label="身份证照片" prop="idPhoto">
          <el-input v-model="form.idPhoto" placeholder="请输入身份证照片" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="idNo">
          <el-input v-model="form.idNo" placeholder="请输入身份证号码" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDevicepersonauthorizedrecord, getDevicepersonauthorizedrecord, delDevicepersonauthorizedrecord, addDevicepersonauthorizedrecord, updateDevicepersonauthorizedrecord, exportDevicepersonauthorizedrecord } from "@/api/lgdz/devicepersonauthorizedrecord";

export default {
  name: "Devicepersonauthorizedrecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 人员授权设备记录表格数据
      devicepersonauthorizedrecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 性别字典
      jobSexOptions: [],
      // 设备方向字典
      deviceDirectionOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jobNum: undefined,
        companyDept: undefined,
        authorizedType: undefined,
        crtime: undefined,
        jobName: undefined,
        facePermission: undefined,
        idcardPermission: undefined,
        faceandcardpermission: undefined,
        idpermission: undefined,
        jobSex: undefined,
        deviceSno: undefined,
        deviceName: undefined,
        deviceDirection: undefined,
        deviceIp: undefined,
        idPhoto: undefined,
        idNo: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_user_sex").then(response => {
      this.jobSexOptions = response.data;
    });
    this.getDicts("CompanyDeviceInfoTable_DeviceDirection").then(response => {
      this.deviceDirectionOptions = response.data;
    });
  },
  methods: {
    /** 查询人员授权设备记录列表 */
    getList() {
      this.loading = true;
      listDevicepersonauthorizedrecord(this.queryParams).then(response => {
        // console.log(response)
        this.devicepersonauthorizedrecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 性别字典翻译
    jobSexFormat(row, column) {
      return this.selectDictLabel(this.jobSexOptions, row.jobSex);
    },
    // 设备方向字典翻译
    deviceDirectionFormat(row, column) {
      return this.selectDictLabel(this.deviceDirectionOptions, row.deviceDirection);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        jobNum: undefined,
        companyDept: undefined,
        authorizedType: undefined,
        crtime: undefined,
        jobName: undefined,
        facePermission: undefined,
        idcardPermission: undefined,
        faceandcardpermission: undefined,
        idpermission: undefined,
        jobSex: undefined,
        authorizedPhotoFirst: undefined,
        authorizedPhotoSecond: undefined,
        authorizedPhotoThird: undefined,
        deviceSno: undefined,
        deviceName: undefined,
        deviceDirection: undefined,
        deviceIp: undefined,
        idPhoto: undefined,
        idNo: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加人员授权设备记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDevicepersonauthorizedrecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改人员授权设备记录";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateDevicepersonauthorizedrecord(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addDevicepersonauthorizedrecord(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除人员授权设备记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDevicepersonauthorizedrecord(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有人员授权设备记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDevicepersonauthorizedrecord(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
